/*
 * 查询我的历史
 * string:keyword 关键词
 * string:startdate 起始日期
 * string:enddate 结束日期
 * number:pageindex 返回页码
 */
function QueryHistory (keyword, startdate, enddate, pageindex) {
    RequestGTMC("listHistoryIncidentByUserId", {
        "txtKeyword" : keyword,
        "createDateStart" : startdate,
        "createDateEnd" : enddate,
        "page" : pageindex,
        "row" : 6
    },
    function(data) {
        console.log("处理中事件列表 获取成功");
        console.log(data);
        var $el = $("#history_event_list");
        if (data.content.length !== 0) {
            $el.empty();
            /*var str = '<dt><span class="history_event">事件</span><span class="history_level">优先级</span><span class="history_time">解决时间</span><span class="history_status">处理状态</span><span class="history_hand">操作</span></dt>';*/
            var str = '<dt><span class="history_event">事件</span><span class="history_level">优先级</span><span class="history_time">解决时间</span><span class="history_noprint">处理状态</span></dt>';
            for (var sub = 0; sub < data.content.length; sub++) {
                str += '<dd><div class="history_tab_tit"><span>' + data.content[sub].create_date + '</span><span>事件单号：<i>' + data.content[sub].code + '</i></span></div><table cellspacing="0" cellpadding="0"><tr><td width="407"><p class="history_tab_text">' + data.content[sub].title + '</p><p class="history_tab_txt">' + (data.content[sub].description?data.content[sub].description:'') + '</p></td><td width="53"><span class="history_tab_level history_tab_lev'
                if (data.content[sub].priority_name === "三级") {
                    str += '3">3';
                } else if (data.content[sub].priority_name === "二级") {
                    str += '2">2';
                } else if (data.content[sub].priority_name === "一级") {
                    str += '1">1';
                } else {
                    str += '4">4';
                }
                /*str += '</span></td><td width="95"><p class="history_tab_time">' + (data.content[sub].solved_date ? data.content[sub].solved_date : "暂无") + '</p></td><td width="140">';*/
                str += '</span></td><td width="95"><p class="history_tab_time">' + (data.content[sub].solved_date ? data.content[sub].solved_date : "暂无") + '</p></td><td width="264">';
                if (data.content[sub].are_feedback) {
                    str += '<p class="history_tab_p">' + data.content[sub].are_feedback + '</p>';
                } else {
                    str += '<p class="history_tab_p">未评价</p>';
                }
                /*str += '<p class="history_tab_p">' + data.content[sub].status + '</p><a href="event.html?id=' + data.content[sub].id + '&code=' + data.content[sub].code + '" class="history_tab_link">事件详情 >></a></td><td width="124">' + (data.content[sub].are_feedback === "待评价" ? '<a href="event.html?id=' + data.content[sub].id + '&code=' + data.content[sub].code + '&appraise=appraise" class="history_tab_btn history_tab_judge">评价</a>' : '') + '<button onclick="window.print();" class="history_tab_btn history_tab_print">打印</button></td></tr></table></dd>';*/
                str += '<p class="history_tab_p">' + data.content[sub].status + '</p><a href="event.html?id=' + data.content[sub].id + '&code=' + data.content[sub].code + '" class="history_tab_link">事件详情 >></a></td></tr></table></dd>';
            }
            if (parseInt(data.total) > 1) {
                console.log(data.total, parseInt(data.total) > 1);
                var pag = "";
                for (var i = 1; i <= data.total; i++) {
                    if (data.page === i) {
                        pag += '<a href="javascript:" class="on">' + i + '</a>';
                    } else {
                        // 如果数据过多就显示一至三，总页数前三，当前页数前后两页，共九页
                        if (i < 4 || i > data.total - 3 || (i < data.page + 2 && i > data.page - 2)) {
                            pag += '<a href="javascript:">' + i + '</a>';
                        } else if (i === data.page - 3 || i === data.page + 3) {
                            pag += '<a href="javascript:" class="none">...</a>';
                        }
                    }
                }
                $("#common_list_pagination").show().children('.pages').html(pag);
                $("#common_list_pagination .pages a").off('click').on('click', function(event) {
                    var pages = $(this).html().trim();
                    if (pages !== "...") {
                        console.log("jump to: " + pages);
                        $("#history_event_list").prepend('<div class="common_load"><img src="../../images/loading.gif"></div>');
                        if ($("#history_search_text").val().trim() !== "可按编号、标题、问题描述查询") {
                            QueryHistory($("#history_search_text").val().trim(), $("#history_search_eday").val().trim(), $("#history_search_sday").val().trim(), pages);
                        } else {
                            QueryHistory("", $("#history_search_eday").val().trim(), $("#history_search_sday").val().trim(), pages);
                        }
                    }
                });
                $("#common_list_pagination .history_btn_listl").click(function(event) {
                    $(this).siblings('.pages').children('.on').prev("a").trigger('click');
                });
                $("#common_list_pagination .history_btn_listr").click(function(event) {
                    $(this).siblings('.pages').children('.on').next("a").trigger('click');
                });
            } else {
                $("#common_list_pagination").removeAttr('style');
            }
            $el.html(str);
        } else {
            $el.html('<div class="common_none">暂无任何相关记录</div>');
        }
        AddDoneCount();
    },
    function() {
        console.log("处理中事件列表 调用失败");
        $("#index_event_process").html('<dt><span class="history_event">事件</span><span class="history_level">优先级</span><span class="history_time">解决时间</span><span class="history_status">处理状态</span><span class="history_hand">操作</span></dt><div class="common_none">暂无任何相关记录</div>');
    },
    function() {
        console.log("处理中事件列表 请求完成");
    });
}

// 调用数据接口
+function() {
    var CommonSucceed = AjaxComplete(1);
    QueryHistory("", "", "", 1);
    CommonBarNotify();
}();

// 事件绑定
-function() {
    //搜索默认文字
    inputFn($('#history_search_text'));
    $(".my_address_conr .my_address_rcon .my_address_ftit").on('click', '.search', function(event) {
        $("#history_event_list").prepend('<div class="common_load"><img src="../images/loading.gif"></div>');
        var $el = $("#history_search_text");
        if ($el.val().trim() !== "可按编号、标题、问题描述查询") {
            console.log("text: " + $el.val().trim() + ", eday: " + $("#history_search_eday").val().trim() + ", sday: " + $("#history_search_sday").val().trim());
            QueryHistory($el.val().trim(), $("#history_search_eday").val().trim(), $("#history_search_sday").val().trim(), 1);
            $el.attr("data-txt", $el.val().trim());
        } else {
            /*alert("请输入关键词。");*/
            QueryHistory("", $("#history_search_eday").val().trim(), $("#history_search_sday").val().trim(), 1);
        }
    });
    $("#history_search_text").on('keydown', function(event) {
        /*if (event.keyCode === 13 && $(this).val().trim() !== "") {
            console.log("text: " + $("#history_search_text").val().trim() + ", eday: " + $("#history_search_eday").val().trim() + ", sday: " + $("#history_search_sday").val().trim());
            QueryHistory($("#history_search_text").val().trim(), $("#history_search_eday").val().trim(), $("#history_search_sday").val().trim(), 1);
        } else {
            alert("请输入关键词。");
        }*/
        if (event.keyCode === 13 && $(this).val().trim() !== "") {
            $("#history_event_list").prepend('<div class="common_load"><img src="../images/loading.gif"></div>');
            QueryHistory($(this).val().trim(), $("#history_search_eday").val().trim(), $("#history_search_sday").val().trim(), 1);
            $(this).attr("data-txt", $(this).val().trim());
        }
    });
    // 分页跳转
    $("#common_list_pagination button").on('click', function(event) {
        var pages = $(this).siblings('label').children('input').val();
        if (pages !== "..." && parseInt(pages)) {
            console.log("jump to: " + pages);
            $("#history_event_list").prepend('<div class="common_load"><img src="../images/loading.gif"></div>');
            if ($("#history_search_text").val().trim() !== "可按编号、标题、问题描述查询") {
                QueryHistory($("#history_search_text").val().trim(), $("#history_search_eday").val().trim(), $("#history_search_sday").val().trim(), pages);
            } else {
                QueryHistory("", $("#history_search_eday").val().trim(), $("#history_search_sday").val().trim(), pages);
            }
        }
    });
    // 概况表显示
    $('.common_float .lbtn1').on('click', function(event) {
        $(".common_shadow .picture_box_index").addClass('on');
        $(".common_shadow").addClass('activate');
    });
    // 概况表关闭
    $(".common_shadow .picture_box_index .close").on('click', function(event) {
        $('.common_shadow .picture_box_index .pics').scrollTop(0)
        $(this).closest('.common_shadow').removeClass('activate');
        $(this).parent('.picture_box_index').removeClass('on');
    });
}();